package com.fancy.learncenter.ui.view;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CartoonFinishWorkBean;
import com.fancy.learncenter.common.LoginUserSharePrefernce;
import com.fancy.learncenter.utils.ImageUtil;
import com.fancy.learncenter.utils.SPUtils;
import com.fancy.learncenter.utils.WXShareUtil;

/**
 * 炫耀一下
 * Created by shiweiwei on 2018/1/16.
 */

public class CartoonShowOffPopu extends PopupWindow {


    private Activity mContext;
    private View rootView;
    private CartoonFinishWorkBean finishWorkBean;
    private SimpleDraweeView headView;
    private TextView headNameText;
    private TextView phraseText;
    private TextView praticeText;
    private TextView answerNumText;
    private ImageView qrImage;
    private TextView weixinText;
    private TextView friendsCircleText;
    private RelativeLayout cancel_layout;
    private String formateData;

    RelativeLayout share_ll;

    public CartoonShowOffPopu(Activity context, CartoonFinishWorkBean bean, String formateData) {
        super(context);
        this.mContext = context;
        this.finishWorkBean = bean;
        this.formateData = formateData;
        initView();
    }

    private void initView() {

        rootView = LayoutInflater.from(mContext).inflate(R.layout.cartoon_showoff_popu, null);
        share_ll = rootView.findViewById(R.id.share_ll);
        headView = (SimpleDraweeView) rootView.findViewById(R.id.head_icon);
        headNameText = (TextView) rootView.findViewById(R.id.head_name);
        phraseText = (TextView) rootView.findViewById(R.id.paragraph_text);
        praticeText = (TextView) rootView.findViewById(R.id.pratice_text);
        answerNumText = (TextView) rootView.findViewById(R.id.answer_num_text);
        qrImage = (ImageView) rootView.findViewById(R.id.learn_center_qrcode);
        weixinText = (TextView) rootView.findViewById(R.id.weixin_text);
        weixinText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                WXShareUtil.getInstance(mContext).sharePicBitmap(ImageUtil.loadBitmapFromView(share_ll), false);
            }
        });
        friendsCircleText = (TextView) rootView.findViewById(R.id.friends_circle_text);
        friendsCircleText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                WXShareUtil.getInstance(mContext).sharePicBitmap(ImageUtil.loadBitmapFromView(share_ll), true);
            }
        });

        cancel_layout = (RelativeLayout) rootView.findViewById(R.id.cancel_layout);

        headView.setImageURI(LoginUserSharePrefernce.getHeaderPath());
        headNameText.setText(LoginUserSharePrefernce.getName());
        answerNumText.setText(finishWorkBean.getRightQuestionCount());
        if (!TextUtils.isEmpty(formateData)) {
            praticeText.setText(formateData);
        }
        phraseText.setText("我已完成" + finishWorkBean.getUnitName() + "教材" + finishWorkBean.getLessonName() + "的学习内容获得了" + ((int) finishWorkBean.getRadishCount()) + "个桃子");

        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        setContentView(rootView);
        cancel_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                dismiss();
            }
        });

    }

}
